Skip to content

fix(chat): preserve attachments and dynamic variables when sending to a new chat (#292064)#310972

Open
maruthang wants to merge 2 commits into
microsoft:mainfrom
maruthang:fix/issue-292064-send-to-new-chat-variables
Open

fix(chat): preserve attachments and dynamic variables when sending to a new chat (#292064)#310972
maruthang wants to merge 2 commits into
microsoft:mainfrom
maruthang:fix/issue-292064-send-to-new-chat-variables

Conversation

@maruthang

Copy link
Copy Markdown
Contributor

What — Sending the current input to a new chat (Ctrl+Shift+Enter) now carries attachments (#file:..., Changes, etc.) and dynamic-variable decorations (#changes) over to the new session instead of dropping them on the floor.

WhySendToNewChatAction.run() only captured the input as a plain text string. The subsequent clearChatSessionPreservingType wiped attachmentModel and ChatDynamicVariableModel, so acceptInput(inputBeforeClear) re-sent the text without its context. #changes came through as raw text with no Changes chip; #file:... lost its file attachment (#292064).

How — Capture widget.attachmentModel.attachments and ChatDynamicVariableModel.variables before the clear. After the clear, setInput(...) the text, then re-add both sets via attachmentModel.addContext(...) and restoredDynamicVariableModel.addReference(...). Finally acceptInput(undefined, { storeToHistory: true }) so the fresh input + restored context flows through the normal submit path.

Test plan — New SendToNewChatAction suite: (1) attachments added before the action persist through to acceptInput; (2) dynamic variable references (e.g. #changes) persist through to acceptInput. Manual per the issue: type review #changes, press Ctrl+Shift+Enter, verify the Changes chip + variable decoration appear in the new session.

Fixes #292064

Copilot AI review requested due to automatic review settings July 6, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug (#292064) where sending the current chat input to a new chat via Ctrl+Shift+Enter dropped attachments (#file:..., Changes) and dynamic-variable decorations (#changes). Previously SendToNewChatAction.run() only captured the plain input text, and clearChatSessionPreservingType wiped the attachmentModel and ChatDynamicVariableModel, so the re-sent text lost its context.

The fix captures the attachments and dynamic variables before clearing, then restores the input text via setInput, re-adds attachments through attachmentModel.addContext(...), re-adds dynamic variables through restoredDynamicVariableModel.addReference(...), and finally submits with acceptInput(undefined, { storeToHistory: true }) so the fresh input plus restored context flows through the normal submit path.

Changes:

  • Capture attachmentModel.attachments and ChatDynamicVariableModel.variables before the session clear, and restore them afterward before submitting.
  • Switch the final submit from acceptInput(inputBeforeClear, …) to setInput(...) + acceptInput(undefined, …) so restored context is included.
  • Add a SendToNewChatAction unit-test suite verifying attachments and dynamic variables persist through the action and that the restore happens after the clear.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.ts Captures and restores attachments and dynamic variables around the session clear so #changes/#file: context survives sending to a new chat.
src/vs/workbench/contrib/chat/test/browser/actions/chatExecuteActions.test.ts Adds a SendToNewChatAction suite with a mock widget asserting restored input/attachments/variables and correct re-add ordering after clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#changes variable goes missing when sending to new chat

3 participants